package com.example.controller;


import com.example.util.IpUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.core.env.StandardEnvironment;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * 三种获取配置以及热更新
 * Environment Value ConfigurationProperties
 */
@RestController
@RequestMapping(value = "/order")
public class Invoke {
    @Autowired
    private Environment environment;

    @Autowired
    private RestTemplate restTemplate;

    @ResponseBody
    @RequestMapping(value = "/getEnv1", method = RequestMethod.GET)
    public String getEnv1() {
        StandardEnvironment standardEnvironment = (StandardEnvironment) environment;
        String ip = environment.getProperty("myAddress");
        System.out.println("myAddress"+ip);
        String url="http://"+ip+":12560/check/from-"+ IpUtil.getRealIp();
        String result  = restTemplate.getForObject(url, String.class);
        return result;
    }
}